
var page=1;
var limit=4;

var count;  //数据总数

var appointlist={};

var account = $api.getStorage('account');

apiready = function(){
	     init(page,limit);
	  	//上拉
		 api.addEventListener({
	        name: 'scrolltobottom'
	     }, function (ret, err) {
	       
	         if(limit<count){
	                 limit+=4;
	                 init(page,limit);
	               
	         }else{
	         
	               api.toast({
		                msg: '下面没有啦...',
		                duration:1000,
		                location: 'bottom'
		            });
	         
	         }
	        
	         
	    });
			
			
		
	};
	
	//初始化数据
	function init(page,limit){
	      
          
	
	      var param='?page='+page+'&limit='+limit+'&account='+account;
	      do_ajax('/app/community/myappoints'+param,'get',{},function(ret,err){
       
				  if(ret){
				                count=ret.count;  //数据总数
				                appointlist=ret.data;
				                
							    var dataHtml = '';
							    if(appointlist.length>0){
							    
							       
							    
							       for(var i=0;i<appointlist.length;i++){
								        dataHtml += '<div class="am-u-sm-12"   id=\'appoint'+i+'\' style="margin-top:5px;border-bottom:1px solid #e5e5e5; padding:8px;">'
							        		
							    		    dataHtml += '<div class="am-u-sm-12">预约编号：'+appointlist[i].appointNo+'  </div>';
							    		    dataHtml += '<div class="am-u-sm-12">预约类别：'+appointlist[i].title+'  </div>';
							    		    dataHtml += '<div class="am-u-sm-12">预约时间：'+appointlist[i].appointTime+'  </div>';
							    		    dataHtml += '<div class="am-u-sm-12">状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态：'+appointlist[i].status+'  </div>';
							    		    dataHtml += ' <div class="am-u-sm-12" style="text-align:right;">';
							    		    dataHtml += '<button class="am-btn am-btn-default" onclick="showappoint(\''+i+'\');"  style="border-radius:5px;color:#3aa1cf;">';
							    		    dataHtml += ' <i class="am-icon-edit"></i>';
							    		    dataHtml += '</button>';
							    		    dataHtml += ' <button class="am-btn am-btn-default" onclick="delappoint(\''+i+'\');" style="border-radius:5px;color:#3aa1cf;">';
							    		    dataHtml += ' <i class="am-icon-trash"></i>';
							    		    dataHtml += '</button>';
							    		    dataHtml += '</div>';

							            dataHtml += '</div>';
							            
							            
							         }
					        
							    }else{
							       
							       dataHtml += '<div  class="am-u-sm-12" style="margin-top:10px;text-align:center">暂无数据...</div>'
							         
							    }
                              
				    
				    
				        $api.html($api.byId('appointlist'), dataHtml);
						
						
						
						
						api.hideProgress();
					    
				       }else{
				            api.alert({
					            msg:('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode)
					        });
					        api.hideProgress();
				       }
			   });
	      
	      
	      
	      
	
};

//预约详情

function showappoint(index){
     openWin('appointinfo',{appoint: appointlist[index]});

};

//删除
function delappoint(index){
       api.confirm({title: '提示',msg:'确定删除吗?',buttons:['确定', '取消']},function(ret,err){
       
			if(ret.buttonIndex == 1){
			     $api.remove($api.byId("appoint"+index));
				 var Ids=appointlist[index]._id;
				 do_ajax("/app/community/delmyappoints",'post',{'Ids':Ids},function(result,err){
					api.hideProgress();
					if(result.resultCode == '0') {
					    toast('删除成功!');
			 		}else{
			 			 toast(result.datas);
			 		}
			 	});
			}
		});
     
}
	
	
	
	